package com.huazi.user.registration.servlet;

import com.huazi.user.registration.service.Imp.UpdateService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改密码的servlet
 */
public class UpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        UpdateService service = new UpdateService();
        String idCard = req.getParameter("idCard");
        String account = req.getParameter("account");
        String phone = req.getParameter("phone");
        String name = req.getParameter("name");
        String pwd = req.getParameter("pwd");
        //获得各种需要的值
        boolean i = service.updatePwd(idCard, account, phone, name, pwd);//如果匹配成功则返回true
        if (i) {

            req.setAttribute("result", "yes");
            //转发到指定页面
            req.getRequestDispatcher("Wang/updatePassword/update.jsp").forward(req, resp);
        } else {
            req.setAttribute("idCard", idCard);
            req.setAttribute("account", account);
            req.setAttribute("phone", phone);
            req.setAttribute("name", name);
            req.setAttribute("pwd", pwd);
            req.setAttribute("result", "no");
            //转发到指定页面
            req.getRequestDispatcher("Wang/updatePassword/update.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
